﻿using System;
using System.Collections.Generic;
using Jayden.Dll.Web.HtmlControls.Descriptions;
using Jayden.Dll.Web.HtmlControls.Generics;
using Jayden.Dll.Web.HtmlControls.Interfaces;

namespace Jayden.Dll.Web.HtmlControls
{
	public class Fieldset : HtmlElement, WithName, WithDisabled, WithForm
	{
		public Fieldset() : base(FieldsetDescription.Instance) { }

		public string Name { get { return this["name"]; } set { this["name"] = value; } }
		public bool Disabled { get { return GetAttributeBool("disabled"); } set { SetAttribute("disabled", value); } }
		public bool Enabled { get { return !Disabled; } set { Disabled = !value; } }
		public string Form { get { return this["form"]; } set { this["form"] = value; } }

		public Legend Legend
		{
			get
			{
				if(m_ChildControls == null || m_ChildControls.Count == 0)
					return null;
				Legend legend = m_ChildControls[0] as Legend;
				return legend;
			}
		}

		public Legend AddLegend(string text = null) { return AddControl(new Legend(text)) as Legend; }
	}
	public class FieldsetDescription : HtmlElementDescription
	{
		public static readonly FieldsetDescription Instance = new FieldsetDescription();
		private FieldsetDescription() : base("fieldset") { }
		public override Type ControlType { get { return typeof(Fieldset); } }
		public override bool IsFlowElement { get { return true; } }
		public override bool OnlyFlowContent { get { return true; } }
		public override string Description { get { return "set of form controls grouped under a common name."; } }
		public override IEnumerable<HtmlElementDescription> PermittedElements { get { yield return LegendDescription.Instance; } }
	}
}
